package com.douxg.fastCoding.web.controller;

import com.douxg.fastCoding.spring.vo.Result;
import com.douxg.fastCoding.web.ConfigTest;
import lombok.Data;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * @Description
 * @Auther douxg
 * @Date 2020/4/16 9:50
 */
@RequestMapping("fc/test")
@RestController
@Data
public class TestController {
    //    @Resource
//    private MongoTemplate mongoTemplate;
//
    @Resource
    private ConfigTest configTest;

    @GetMapping("test")
    public Result test(HttpServletRequest req, HttpServletResponse response) {
        HttpSession session = req.getSession();

        LocalDateTime now = LocalDateTime.now();
        File file = new File(".");
        String absolutePath = file.getAbsolutePath();
        Long a = new Date().getTime();
        System.out.println(a);
        return Result.success().setData(session.getAttribute("username"));
    }

    @GetMapping("login")
    public Result login(HttpServletRequest req, HttpServletResponse response) {
        HttpSession session = req.getSession();
        session.setAttribute("username", "dxg");
        return Result.success().setData("login success");
    }

    @GetMapping("logout")
    public Result logout(HttpServletRequest req, HttpServletResponse response) {
        HttpSession session = req.getSession();
        session.invalidate();
        return Result.success().setData("logout success");
    }
//
//    @GetMapping("mongo")
//    public Result mongo(@RequestParam("name") String name) {
//        Query query = new Query(Criteria.where("UNIT_NAME").is(name));
//        return Result.success().setData(mongoTemplate.find(query, Map.class, "MI_A_UNIT"));
//    }
//
//    @PostMapping("import")
//    public Result importFile(@RequestParam MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
//        if (file == null) {
//            return Result.error().setMsg("文件不能为空");
//        }
//        LocalDateTime now = LocalDateTime.now();
//        return Result.success().setData(now);
//    }
}
